<?php
namespace Home\Controller;
use Think\Controller;
class TestController extends Controller {
    public function index(){
        $this->display();
    }
    public function geetestweb()
    {
        var_dump($_SESSION);
        $this->display();
    }
    public function StartCaptchaServlet()
    {
        import('geetestlib',THINK_PATH.'Common\geetest','.php');
        $gt = new \GeetestLib('8adec391f825e0bf7abd53c8c028f961', '90b01d41935febbb1d89088249819ad8');
        $user_id = "qzone";
        $status = $gt->pre_process($user_id);
        $_SESSION['gtserver'] = $status;
        $_SESSION['user_id'] = $user_id;
        echo $gt->get_response_str();
    }
    public function VerifyLoginServlet()
    {
        import('geetestlib',THINK_PATH.'Common\geetest','.php');
        $GtSdk = new \GeetestLib('8adec391f825e0bf7abd53c8c028f961', '90b01d41935febbb1d89088249819ad8');
        $user_id = $_SESSION['user_id'];
        if ($_SESSION['gtserver'] == 1) {
            $result = $GtSdk->success_validate($_POST['geetest_challenge'], $_POST['geetest_validate'], $_POST['geetest_seccode'], $user_id);
            if ($result) {
                echo 'Yes!';
            } else{
                echo 'No';
            }
        }else{
            if ($GtSdk->fail_validate($_POST['geetest_challenge'],$_POST['geetest_validate'],$_POST['geetest_seccode'])) {
                echo "yes";
            }else{
                echo "no";
            }
        }
    }
}